package edu.study.api.common.constraints;

import org.apache.commons.lang.ArrayUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

public class ValidStringsValidator implements ConstraintValidator<ValidStrings, String> {

    private String[] valueList;

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (value == null || !ArrayUtils.contains(valueList, value)) {
            return false;
        }
        return true;
    }

    @Override
    public void initialize(ValidStrings constraintAnnotation) {
        valueList = constraintAnnotation.value();
    }
}
